<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>项目购买</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" href="../../css/public-heder-Reset.css">
	<link rel="stylesheet" href="../../css/Project-Purchase.css">
</head>
<body>
	<!-- page_box -->
	<div class="page-box">
		<!-- header -->
		<header class="page-header">
			<a href="javascript:history.go(-1)" class="back"></a>
			<p class="pege-name"></p>
			<a class="Reset"></a>
		</header>
		<div class="liubai"></div>
		<!-- header /-->
		<!-- investment-data -->
		<div class="context">
			<!-- 异步请求数据 -->
		</div>
		<div class="Expectation">
			<div class="ExpeBox">
				<p>计算预期收益</p>
				<div class="money">
					<input type="text" placeholder="请输入购买金额，最低1000元" maxlength="8" />
					<span>元</span>
				</div>
				<div class="profit">
					<div class="profitLt clear">
						<p></p>
						<i>0.00</i>
					</div>
					<div class="profitRt clear">
						<em class="fl">理财期限</em>
						<em class="fr">预期收益(元)</em>
					</div>
				</div>
				<div class="cancel"></div>
			</div>
		</div>
		<!-- Buy now fixed-->
		<footer class="Buy-now">			
			<span class="Calculator"></span>
			<button class="submitBtn" disabled="disabled"></button>
		</footer>
		<!-- Buy now fixed -->
	</div>
	<!-- page_box /-->
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
	<script type="text/javascript" src="../../js/http-url.js"></script>
	<script type="text/javascript">
	// 项目基本信息；
		function projectInfo(even){
			var data_attr_id=$(even).attr('data-attr-id');
			window.localStorage.setItem("data_attr_id",data_attr_id);
			window.location.href="Project-infor.html";
		}
		$(function(){
			var status,lu,tin,tex,r_tin,tlu;
			var projectsId=window.localStorage.getItem("projectsId");
			// ajax请求数据
			ajaxRequest('/api/projects/'+projectsId+'',null,function(data){
				status=data.data.data.status;
				r_tin=data.data.data.profit_rule_r_num;
				tlu=data.data.data.profit_rule;
				lu=data.data.data.profit_rule;
				tin=data.data.data.profit_rule_num;
				tex=data.data.data.profit_rule_cate;
				$('.profit .profitLt').find('p').text(r_tin+tex);
				$('.pege-name').text(data.data.data.title);
				$(data.data.one).appendTo('.context');
				$('.Calculator').addClass(status);
				$('.submitBtn').addClass(status);
				if (status=='rush'){
					$('.submitBtn').text('立即购买').attr('disabled',false);
				}else if (status=='full') {
					$('.submitBtn').text('满标');
				}else if(status=='payment'){
					$('.submitBtn').text('还款中');
				}else if(status=='finish') {
					$('.submitBtn').text('还款完成');
				}
			},true);
			//计算器
			$('.Calculator').click(function(){
				$('.Expectation').show();
			});
			// 取消计算器
			$('.cancel').click(function(){
				$('.Expectation').hide();
				$('.profit .profitLt').find('i').text('0.00');
				$('.money').find('input').val("");
			});
			// 刷新页面
			$('.Reset').click(function(){
				location.reload() 
			});
			// 计算收益
			$('.money').find('input').on('keyup',function(){
				this.value=this.value.replace(/[^\d]/g,'')
				var Mym=$('.money').find('input').val().trim();
				$('.profit .profitLt').find('i').text((~~(Mym*tlu*tin))/100)
			});
			// 买标
			$('.Buy-now').find('button').click(function(){
				ajaxRequest('/api/user/fb/card/pay',null,function(data){
					if(data.m_status!=200){
						return;
					}else {
						window.location.href="Project-payment.html"	
					}
				},false);
			});
		});
	</script>
</body>
</html>